package a07_二叉树;

/**
 * <p>
 * a24_二叉搜索树的最小绝对差复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/4/16
 */
public class a24_二叉搜索树的最小绝对差复习3 {
    public int getMinimumDifference(TreeNode root) {
        traversal(root);
        return minDiff;
    }

    private TreeNode prevNode = null;
    private int minDiff = Integer.MAX_VALUE;

    public void traversal(TreeNode root) {
        if (root == null) {
            return;
        }

        traversal(root.left);

        if (prevNode != null) {
            minDiff = Math.min(minDiff,root.val - prevNode.val);
        }
        prevNode = root;

        traversal(root.right);
    }
}
